﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.DAO;

public partial class Admin_ucControl_ucGioiThieu : System.Web.UI.UserControl
{
    TblGioithieuDAO gioithieuDAO = new TblGioithieuDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session[Global.SESSION_ADMIN_USER] == "" || Session[Global.SESSION_ADMIN_USER] == null)
            {
                Response.Redirect("~/Admin/Login.aspx");
            }
            loadGioithieu();
            LoadDetail();
        }
    }

    private void loadGioithieu()
    {
        grGioithieu.DataSource = gioithieuDAO.GetAlll();
        grGioithieu.DataBind();
    }

    private void LoadDetail()
    {
        string id = Request.QueryString["id"];
        DataTable table = gioithieuDAO.GetGioithieuByID(Convert.ToInt32(id));
        foreach (DataRow dr in table.Rows)
        {
            txtnoidung.Content = dr["Noidung"].ToString();
        }
    }

    protected void btnLuu_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];

        TblGioithieu gioithieu = new TblGioithieu();
        gioithieu.Noidung = Server.HtmlDecode(txtnoidung.Content);

        if (id == null || id == "")
        {
            gioithieuDAO.InGioithieu(Server.HtmlDecode(txtnoidung.Content));
            loadGioithieu();

        }
        else
        {
            gioithieuDAO.upGioithieu(Server.HtmlDecode(txtnoidung.Content), Convert.ToInt32(id));
            loadGioithieu();
        }
    }
}
